package com.LachesismStorm.lachesism.controller;

import com.LachesismStorm.lachesism.core.common.response.ResponseResult;
import com.LachesismStorm.lachesism.service.PubService;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

/**
 * @Author: lachesism
 * @Date: 2022/11/07/17:28
 * @Description:
 */
@Api(tags = "公共模块管理")
@RestController
@RequestMapping("/pub")
public class PubController {
    @Resource
    private PubService pubService;

    @ApiOperation(value = "图片上传")
    @PostMapping("/img")
    public ResponseResult upload(@RequestParam("file") MultipartFile file) {
        Map<String, String> retMap = pubService.uploadImg(file);
        return ResponseResult.success(retMap);
    }

    @PostMapping("/uploadImage")
    public ResponseResult uploadImage(@RequestParam("file") MultipartFile file) throws Exception {
        Map<String, String> imgMap = pubService.uploadImage(file);
        return ResponseResult.success(imgMap, null);
    }

    @PostMapping("/uploadDoc")
    public ResponseResult uploadFile(@RequestParam("file") MultipartFile file) {
        String code = pubService.uploadFile(file);
        return ResponseResult.success(code, "上传成功");
    }

    @ApiOperation(value = "上传照片改尺寸")
    @PostMapping("/uploadPic")
    public ResponseResult getHundredPic(@RequestParam("file") MultipartFile file) {
        String url = pubService.uploadPic(file);
        return ResponseResult.success(url, "上传成功");
    }

}
